/**
 * 
 */
package com.hibernate.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;
import org.hibernate.validator.constraints.Length;

/**
 * @author lijt
 * 
 */
@Entity
@Table(name = "INDUSTRY_MAPPING", uniqueConstraints = {
		@UniqueConstraint(columnNames = { "USER_ID",  "OTHER_CODE" }),
		@UniqueConstraint(columnNames = { "USER_ID",  "INDUSTRY_ID" }) })
public class IndustryMapping extends BaseEntity implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7419023991201120939L;

	/**
	 * 
	 */
	public IndustryMapping() {
	}

	private Long id;
	@NotNull
	private Long userId;
	@Length(max=255)
	private String otherCode;

	private Industry industry;

	private Long industryId;

	private AcctUser acctUser;

	public void setAcctUser(AcctUser acctUser) {
		this.acctUser = acctUser;
	}

	@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE}, fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "USER_ID", insertable = false, updatable = false) })
	public AcctUser getAcctUser() {
		return acctUser;
	}

	
	@Id
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "native") 
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	@Column(name = "USER_ID", unique = false, nullable = false, insertable = true, updatable = true, length = 20)
	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}
	@Column(name = "OTHER_CODE", unique = false, nullable = true, insertable = true, updatable = true, length = 255)
	public String getOtherCode() {
		return otherCode;
	}

	public void setOtherCode(String otherCode) {
		this.otherCode = otherCode;
	}

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY)
	@JoinColumn(name = "INDUSTRY_ID", insertable = false, updatable = false)
	public Industry getIndustry() {
		return industry;
	}

	public void setIndustry(Industry industry) {
		this.industry = industry;
	}
	@Column(name = "INDUSTRY_ID", insertable = true, updatable = true, length = 20)
	public Long getIndustryId() {
		return industryId;
	}

	public void setIndustryId(Long industryId) {
		this.industryId = industryId;
	}


	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof IndustryMapping))
			return false;
		IndustryMapping castOther = (IndustryMapping) other;
		return new EqualsBuilder().append(id, castOther.id)
				.append(userId, castOther.userId)
				.append(otherCode, castOther.otherCode)
				.append(industry, castOther.industry)
				.append(industryId, castOther.industryId)
				.append(acctUser, castOther.acctUser).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(id).append(userId)
				.append(otherCode).append(industry).append(industryId)
				.append(acctUser).toHashCode();
	}

	@Transient
	@Override
	public String getTarget() {
		// TODO Auto-generated method stub
		return null;
	}
	@Transient
	@Override
	public Long getTargetId() {
		// TODO Auto-generated method stub
		return null;
	}
	@Transient
	@Override
	public String getTargetName() {
		// TODO Auto-generated method stub
		return null;
	}
	
}
